#include <bits/stdc++.h>

using namespace std;

void init(vector<int> &father)
{
    for (size_t i = 1; i < father.size(); i++)
    {
        father[i] = i;
    }
}

int find(int x, vector<int> &father)
{
    if (x == father[x])
    {
        return x;
    }
    else
    {
        father[x] = find(father[x], father);
        return father[x];
    }
}

bool is_same_root(int u, int v, vector<int> &father)
{
    u = find(u, father);
    v = find(v, father);
    if (u == v)
    {
        return true;
    }
    else
    {
        return false;
    }
}

void join(int u, int v, vector<int> &father)
{
    u = find(u, father);
    v = find(v, father);
    if (u == v)
    {
        return;
    }
    else
    {
        father[v] = u;
    }
}

int main()
{
    int n, m;
    cin >> n >> m;
    vector<int> father(n + 1, 0);
    init(father);
    while (m--)
    {
        int u, v;
        cin >> u >> v;
        join(u, v, father);
    }
    int u, v;
    cin >> u >> v;
    if (is_same_root(u, v, father))
    {
        cout << 1 << endl;
    }
    else
    {
        cout << 0 << endl;
    }
    return 0;
}